//利用pinia管理数据
import { defineStore } from 'pinia'
//引入ts
import { HospitalDetail, DeparmentResponseData, LoginData } from '@/api/hospital/type';
import type { detailState } from './interface';
//pinia仓库写法,组合式API,选择式API写法
//引入API
//yi==医院详情
import { reqHospitalDetail, reqHospitalDepartment } from '@/api/hospital';
//医院科室
const useDetailStore = defineStore('Detail', {
    state: (): detailState => {
        return {
            //医院详情的数据
            hospitalInfo: ({} as any),
            departmentArr: []
        }
    },
    actions: {
        //获取医院详情数据
        async getHospital(hoscode: string) {
            let result: HospitalDetail = await reqHospitalDetail(hoscode);
            if (result.code == 200) {
                this.hospitalInfo = result.data;
            }
        },
        //医院部分数据
        async getDepartment(hoscode: string) {
            let result: DeparmentResponseData = await reqHospitalDepartment(hoscode)
            if (result.code == 200) {
                this.departmentArr = result.data;
                return 'ok'
            }
            else {
                return Promise.reject(new Error(result.message))
            }
        },


    },
    getters: {

    }
});
export default useDetailStore